package flc.ast.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ImageUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.picselect.entity.SelectMediaEntity;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.TimeUtil;

public class PictureAdapter extends StkProviderMultiAdapter<SelectMediaEntity> {

    public PictureAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(125));
        addItemProvider(new PictureProvider());
    }

    private boolean isEdit = false;

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class PictureProvider extends BaseItemProvider<SelectMediaEntity> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_picture;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, SelectMediaEntity bean) {
            Glide.with(getContext()).load(bean.getPath())
                    .into((ImageView) baseViewHolder.getView(R.id.ivPictureItemImg));
            if (isEdit) {
                baseViewHolder.getView(R.id.ivPictureItemSel).setVisibility(View.VISIBLE);
                if (bean.isChecked()) {
                    baseViewHolder.setImageResource(R.id.ivPictureItemSel, R.drawable.axz);
                    baseViewHolder.getView(R.id.llPictureItemBg).setVisibility(View.VISIBLE);
                } else {
                    baseViewHolder.setImageResource(R.id.ivPictureItemSel, R.drawable.awxz);
                    baseViewHolder.getView(R.id.llPictureItemBg).setVisibility(View.GONE);
                }
            } else {
                baseViewHolder.getView(R.id.ivPictureItemSel).setVisibility(View.GONE);
            }
        }
    }
}
